﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace SimpleData.ObjectModel
{

	/// <summary>
	/// Objeto utilizado para definir o padrão do namespace utilizado
	/// </summary>
	public sealed class NamespaceScope : IDisposable
	{
		private NamespaceScope lastScope;
		private INamespaceContainer container;

		public NamespaceScope( string ns )
			: this( ns, null )
		{ }

		internal NamespaceScope( string ns, INamespaceContainer container )
		{
			Contract.Requires<ArgumentNullException>( !String.IsNullOrEmpty( ns ) );

			this.Namespace = ns;
			this.container = container;
			if ( container != null )
				this.lastScope = container.UsingNamespace;
		}

		public string Namespace
		{
			get;
			private set;
		}

		public void Dispose()
		{
			if ( this.container != null )
				container.UsingNamespace = this.lastScope;
		}
	}
}
